<div class="eject_con">
    <div id="warning"></div>
    <?php if ($output['order_info']) {?>
    <?php foreach($output['order_info'] as $order_id => $order) { ?>

        <form id="changeform" method="post" action="index.php?act=menu_1018&op=order_modify">
            <input type="hidden" name="form_submit" value="ok" />
            <input type="hidden" name="id" value="<?php echo $order['id']; ?>" />
            <dl>
                <dt><?php echo $lang['store_order_sn'].$lang['nc_colon'];?></dt>
                <dd><span class="num"><?php echo $order['id']; ?></span></dd>
            </dl>
			<dl>
                <dt>买&nbsp;家：</dt>
                <dd><input type="text" class="text" id="goods_amount" name="buyer" value="<?php echo $order['buyer']; ?>"></dd>
            </dl>
            <dl>
                <dt><font class="red">*</font>手机号码：</dt>
                <dd><input type="text" class="text" name="phone" value="<?php echo $order['phone']; ?>"></dd>
            </dl>
            <dl>
                <dt><font class="red">*</font>商品选择：</dt>
                <dd>
				<input type="hidden" class="text" name="goods_name" value="<?php echo $order['goods_name']; ?>"/>
				<input type="hidden" class="text" name="goods_price" value=""/>

					<select name="goods_name_show" id="">
						<option value="">请选择</option><!--这行不要删，下面保持数据格式，计算程序才能运行-->

                        <?php
                                foreach ($output['goods_list']  as $_key=>$_value){   ?>

                                    <option value="<?php echo $_key ?>"

                                            <?php
                                                      if ($order['goods_name']== $_key )
                                                          echo 'selected'
                                            ?>

                                    ><?php echo $_key; ?>/<?php echo $_value; ?>￥</option>

                                  <?php }?>




					</select>
                </dd>
            </dl>
            <dl>
                <dt><font class="red">*</font>发货状态：</dt>
                <dd>
                    <select name="goods_state">

                        <?php
                        foreach ($output['goods_state']  as $_key=>$_value){   ?>

                            <option value="<?php echo $_key ?>"

                                <?php
                                if ($order['is_state']== $_key )
                                    echo 'selected'
                                ?>

                            ><?php echo $_value; ?>
                            </option>

                        <?php }?>

                    </select>
                </dd>
            </dl>
            <dl>
                <dt>数量：</dt>
                <dd>
                    <input type="text" class="text" id="goods_amount" name="count" value="<?php echo $order['count']; ?>">
                </dd>
            </dl>
            <dl>
                <dt>订单金额：</dt>
                <dd>
                    <input type="text" class="text" id="goods_amount" name="price" value="<?php echo $order['price']; ?>">
                </dd>
            </dl>
			<div class="alert-error tc">警告：未填正确写买家手机号码、选择商品，无法提交表单!</div>
            <dl class="bottom">
                <dt>&nbsp;</dt>
                <dd>
                    <input type="submit" class="submit" id="confirm_button" value="<?php echo $lang['nc_ok'];?>" />
                </dd>
            </dl>
			
        <?php } ?>
        </form>
    <?php } else { ?>
        <p style="line-height:80px;text-align:center">该订单并不存在，请检查参数是否正确!</p>

    <?php } ?>
</div>
<script type="text/javascript">

    $(function(){
        $('#changeform').validate({
            errorLabelContainer: $('#warning'),
            invalidHandler: function(form, validator) {
                var errors = validator.numberOfInvalids();
                if(errors){ $('#warning').show();}else{ $('#warning').hide(); }
            },
            submitHandler:function(form){
                ajaxpost('changeform', '', '', 'onerror');
            },
            rules : {
                order_amount : {
                    required : true,
                    number : true
                }
            },
            messages : {
                order_amount : {
                    required : '<?php echo $lang['store_order_modify_price_gpriceerror'];?>',
                    number : '<?php echo $lang['store_order_modify_price_gpriceerror'];?>'
                }
            }
        });
submit_check(true)
$("select[name=goods_name_show]").val($("input[name=goods_name]").val())
get_p()

$("input[name=phone]").bind('input propertychange',function(){
	var len = $(this).val().length
	var phone = $(this).val()
	if(len>0 && checkPhone(phone)){
		submit_check(true)
	}else{
		submit_check(false)
	}
})

$("select[name=goods_name_show]").bind('change',function(){
	get_p()
})

$("input[name=count]").bind('input propertychange',function(){
	get_p()
})

$("input[name=count]").change(function(){
	if($("input[name=count]").val().length<1){
		$("input[name=count]").val(1)
		get_p()
	}
})

function get_p(){

	var p = $("select[name=goods_name_show]").find("option:selected")
	var n = $("input[name=count]").val()
	if(n.length>0){
		if (n!=null && n!="" && isNaN(n)){
			var n = 1
			$("input[name=count]").val(n)
		}
	
		if(p.index()!=0){
			p = p.text().split("/")
			var k = p
			p = p[1].match(/[0-9].*.[0-9]/g);

			$("input[name=goods_price]").val(p)
			$("input[name=price]").val(toDecimal2(p*n))

			$("input[name=goods_name]").val(k[0])
		}
	}
}

function submit_check(boo){


	if(boo){
		$("input[type=submit]").removeAttr("disabled")
		$(".alert-error").hide()
	}else{
		$("input[type=submit]").attr("disabled","disabled")
		$(".alert-error").show()
		
	}
}

function toDecimal2(x) { 
      var f = parseFloat(x); 
      if (isNaN(f)) { 
        return false; 
      } 
      var f = Math.round(x*100)/100; 
      var s = f.toString(); 
      var rs = s.indexOf('.'); 
      if (rs < 0) { 
        rs = s.length; 
        s += '.'; 
      } 
      while (s.length <= rs + 2) { 
        s += '0'; 
      } 
      return s; 
} 

function checkPhone(phone){
    if(!(/^1[34578]\d{9}$/.test(phone))){  
        return false; 
    }
	return true;
}

    });
</script>